use crate::data::cors::CorsOptions;
use crate::model::user::UserIdNum;
use rocket::Route;

static CREATE_OPTIONS: CorsOptions = CorsOptions {
    allowed_methods: &["POST"],
    allowed_headers: &["Authorization"],
};

#[options("/create")]
async fn create_cors() -> &'static CorsOptions {
    &CREATE_OPTIONS
}

static USER_OPTIONS: CorsOptions = CorsOptions {
    allowed_methods: &["DELETE", "PATCH"],
    allowed_headers: &["Authorization"],
};

#[options("/<_id>")]
async fn user_cors(_id: UserIdNum) -> &'static CorsOptions {
    &USER_OPTIONS
}

static LIST_OPTIONS: CorsOptions = CorsOptions {
    allowed_methods: &["GET"],
    allowed_headers: &["Authorization"],
};

#[options("/")]
async fn list_cors() -> &'static CorsOptions {
    &LIST_OPTIONS
}

static UPDATE_PASSWORD_CORS: CorsOptions = CorsOptions {
    allowed_methods: &["POST"],
    allowed_headers: &["Authorization"],
};

#[options("/password/update")]
async fn update_password_cors() -> &'static CorsOptions {
    &UPDATE_PASSWORD_CORS
}

pub fn route() -> Vec<Route> {
    routes![create_cors, user_cors, list_cors, update_password_cors]
}
